
<style>
.myselect{
    width: 200px;
    border-radius: 3px;
    border: #00aeff solid 1px;
    padding: 2px 0px;
    font-size: 14px;
    color: #777171;
}
</style>
<div class="row-content am-cf">
    <div class="row">

        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-cf">管理</div>
                </div>
                <div class="widget-body am-fr">

                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <a class="am-btn am-btn-default am-btn-success am-radius"
                                       href="<?php echo url('add',['sitep'=>$sitep , 'sites'=>$sites]); ?>">
                                        <span class="am-icon-plus"></span> 新增
                                    </a>

                                    <a class="am-btn am-radius am-btn-primary show-btn" data-type="1"
                                       href="javascript:;;">
                                        <span class="am-icon-check-square-o"></span> 显示
                                    </a>

                                    <a class="am-btn am-radius am-btn-danger show-btn"  data-type="2"
                                       href="javascript:;;">
                                        <span class="am-icon-square-o"></span> 隐藏
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="am-u-sm-12">
                        <form class="am-form-inline" role="form">
                            <div class="am-form-group">
                                <select  class="myselect sitelist"  name="sites" width="400">
                                        <option value="1" <?php echo $sites==1 ? 'selected' : ''; ?>>===所有===</option>
                                    <?php foreach($siteList as $v): ?>
                                        <option value="<?php echo $v['id']; ?>" <?php echo $sites==$v['id'] ? 'selected' : ''; ?>><?php echo $v['bwtitle']; ?></option>
                                    <?php endforeach; ?>
                                </select>
                            </div>
                            <div class="am-form-group">
                                <a class="am-btn am-radius am-btn-xs am-btn-warning search-bw">
                                <span class="am-icon-search"></span> 查找</a>
                            </div>
                        </form>
                    </div>

                    <div class="am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped
                         tpl-table-black am-text-nowrap">
                            <thead>
                            <tr>
                                <th><input type="checkbox" id="check"></th>
                                <th>ID</th>
                                <th>名称</th>
                                <th>类型</th>
                                <th>宽高</th>
                                <th>排序</th>
                                <th>版位</th>
                                <th>显示</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                                <?php if (!$list->isEmpty()): foreach ($list as $item): ?>
                                <tr>
                                    <td class="am-text-middle"><input class="ids" type="checkbox" name="ids[]"	value="<?php echo $item['id']; ?>"></td>
                                    <td class="am-text-middle"><?php echo $item['id']; ?></td>
                                    <td class="am-text-middle"><p class="item-title"><?php echo $item['title']; ?></p></td>
                                    <td class="am-text-middle">
                                        <?php if($item['types'] == 1): ?>
                                            <a href="<?php echo $item['thumb']; ?>" target="_blank">图片</a>
                                        <?php else: ?>
                                            文字
                                        <?php endif; ?>
                                    </td>
                                    <td class="am-text-middle"><?php echo $item['width'].' * '.$item['height']; ?></td>
                                    <td class="am-text-middle"><?php echo $item['sorts']; ?></td>
                                    <td class="am-text-middle"><?php echo $item['site_name']; ?></td>
                                    <td class="am-text-middle">
                                        <?php if($item['status'] == 1): ?>
                                            <span class="x-color-green">显示</span>
                                        <?php else: ?>
                                            <span class="x-color-red">隐藏</span>
                                        <?php endif; ?>
                                    </td>
                                    <td class="am-text-middle">
                                        <div class="tpl-table-black-operation">
                                            <a href="<?php echo url('edit',
                                                ['id' => $item['id'] , 'sitep'=>$sitep , 'sites'=>$sites]); ?>">
                                                <i class="am-icon-pencil"></i> 编辑
                                            </a>
                                            <a href="javascript:;" class="item-delete tpl-table-black-operation-del"
                                               data-id="<?php echo $item['id']; ?>">
                                                <i class="am-icon-trash"></i> 删除
                                            </a>
                                        </div>
                                    </td>
                                </tr>
                                
                                <?php endforeach; else: ?>
                                <tr>
                                    <td colspan="9" class="am-text-center">暂无记录</td>
                                </tr>
                                <?php endif; ?>
                            </tbody>
                        </table>
                       
                    </div>

                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr"><?php echo $list->render(); ?> </div>
                        <div class="am-fr pagination-total am-margin-right">
                            <div class="am-vertical-align-middle">总记录：<?php echo $list->total(); ?></div>
                        </div>
                    </div>

                </div>

            </div>
        </div>
    </div>
</div>

<script>
$(function(){

    /**
    *全选
     */
    $('#check').click(function(){
        var checkStatus = $('#check').prop('checked');
        $('.ids').each(function(){
            $(this).prop('checked',checkStatus);
        });
    });

    /**
    * 
     */
    function getCheck(){
        var ids = [];
        $('.ids').each(function(){
            var id = $(this).val();
            if($(this).prop('checked')){
                ids.push(id);
            }
        });
        return ids;
    }

    var url = "<?php echo url('delete'); ?>";
    $('.item-delete').delete('id', url);

    $('.search-bw').click(function(){
        var id = $('.sitelist').val();
        var url = "<?php echo url('index' , ['sitep'=>$sitep]); ?>";
        if(url.indexOf('?') > 0){
            url += '&sites=' + id;
        }else{
            url += '?sites=' + id;
        }
        location.href = url;
    });
    /**
    *显示隐藏
     */
    $('.show-btn').click(function (){
        ids = getCheck();
        type = $(this).data('type');
        var ii = layer.load(0,{shade: [0.8,'#000']});
        $.post('<?php echo url('change') ?>' , {ids:ids ,field:'status' , value:type} , function(data){
            layer.msg(data.msg);
            layer.close(ii);
            setTimeout(() => {
                window.location.reload();
            }, 1500);
        });
    });
});
</script>

